<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
	<th:block th:include="include :: header('商城签到')" />
	<style type="text/css">
		.fixed-table-toolbar {
			display: none;
		}
	</style>
</head>

<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<div class="nav-tabs-custom">
			<ul class="nav nav-tabs">
				<li class="active">
					<a href="#tab-sign-config" data-toggle="tab" aria-expanded="true">签到规则</a>
				</li>
				<li><a href="#tab-sign-list" data-toggle="tab" aria-expanded="false">签到记录</a></li>
			</ul>
			<div class="tab-content">
				<div class="tab-pane active" id="tab-sign-config">
					<div class="row">
						<form id="configForm">
							<div class="col-sm-12 table-striped">
								<table id="config-table"></table>
							</div>
						</form>
					</div>
				</div>
				<div class="tab-pane" id="tab-sign-list">
					<div class="row">
						<form id="signForm">
							<div class="col-sm-12">
								<div class="select-list">
									<ul>
										<li>
											<label>会员账号：</label>
											<input type="text" name="loginName" />
										</li>
										<li>
											<label>会员昵称：</label>
											<input type="text" name="nickName" />
										</li>
										<li>
											<a class="btn btn-primary btn-rounded btn-sm"
												onclick="$.table.search('signForm')"><i
													class="fa fa-search"></i>&nbsp;搜索</a>
											<a class="btn btn-warning btn-rounded btn-sm"
												onclick="$.form.reset('signForm')"><i
													class="fa fa-refresh"></i>&nbsp;重置</a>
										</li>
									</ul>
								</div>
							</div>
							<div class="col-sm-12 table-striped">
								<table id="sign-table"></table>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>

	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "shop/member/sign";
		var datas = [[${@dict.getType('shop_yes_no')}]];
		$(function () {
			var options = {
				id: 'config-table',
				url: prefix + "/config",
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				removeUrl: prefix + "/remove/{id}",
				modalName: "签到设置",
				pagination: false,
				columns: [
					{
						field: 'index',
						align: 'center',
						title: "序号",
						formatter: function (value, row, index) {
							return $.table.serialNumber(index);
						}
					},
					{
						field: 'dayNum',
						title: '签到天数',
						align: 'center',
						formatter: function (value, row, index) {
							return "第" + toChinese(value) + "天";
						}
					},
					{
						field: 'isPoint',
						title: '积分奖励',
						align: 'center',
						formatter: function (value, row, index) {
							return $.table.selectDictLabel(datas, value);
						}
					},
					{
						field: 'isGrowth',
						title: '成长值奖励',
						align: 'center',
						formatter: function (value, row, index) {
							return $.table.selectDictLabel(datas, value);
						}
					},
					{
						field: 'title',
						title: '奖励内容',
						align: 'center'
					},
					{
						field: 'sort',
						title: '排序号',
						align: 'center'
					},
					{
						title: '操作 ' + '<a onclick="$.operate.add()"><i class="fa fa-plus"></i></a>',
						align: 'center',
						formatter: function (value, row, index) {
							console.log
							var actions = [];
							actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.configId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
							actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.configId + '\')"><i class="fa fa-remove"></i>删除</a>');
							return actions.join('');
						}
					}]
			};
			$.table.init(options);

			var options2 = {
				id: 'sign-table',
				url: prefix + "/list",
				modalName: "签到记录",
				columns: [
					{
						field: 'index',
						align: 'center',
						title: "序号",
						formatter: function (value, row, index) {
							return $.table.serialNumber(index);
						}
					},
					{
						field: 'loginName',
						title: '会员账号',
						align: 'center'
					},
					{
						field: 'nickName',
						title: '会员昵称',
						align: 'center'
					},
					{
						field: 'signDays',
						title: '连续天数',
						align: 'center',
						formatter: function (value, row, index) {
							return toChinese(row.signDays) + "天";
						}
					},
					{
						field: 'point',
						title: '奖励积分',
						align: 'center'

					},
					{
						field: 'title',
						title: '奖励说明',
						align: 'center'
					},
					{
						field: 'createTime',
						title: '签到时间',
						align: 'center'
					}]
			};
			$.table.init(options2);
		});

		//阿拉伯数字转换为简写汉字
		function toChinese(Num) {
			for (i = Num.length - 1; i >= 0; i--) {
				Num = Num.replace(",", "")//替换Num中的“,”
				Num = Num.replace(" ", "")//替换Num中的空格
			}
			if (isNaN(Num)) { //验证输入的字符是否为数字
				//alert("请检查小写金额是否正确");
				return;
			}
			//字符处理完毕后开始转换，采用前后两部分分别转换
			part = String(Num).split(".");
			newchar = "";
			//小数点前进行转化
			for (i = part[0].length - 1; i >= 0; i--) {
				if (part[0].length > 10) {
					//alert("位数过大，无法计算");
					return "";
				}//若数量超过拾亿单位，提示
				tmpnewchar = ""
				perchar = part[0].charAt(i);
				switch (perchar) {
					case "0": tmpnewchar = "零" + tmpnewchar; break;
					case "1": tmpnewchar = "一" + tmpnewchar; break;
					case "2": tmpnewchar = "二" + tmpnewchar; break;
					case "3": tmpnewchar = "三" + tmpnewchar; break;
					case "4": tmpnewchar = "四" + tmpnewchar; break;
					case "5": tmpnewchar = "五" + tmpnewchar; break;
					case "6": tmpnewchar = "六" + tmpnewchar; break;
					case "7": tmpnewchar = "七" + tmpnewchar; break;
					case "8": tmpnewchar = "八" + tmpnewchar; break;
					case "9": tmpnewchar = "九" + tmpnewchar; break;
				}
				switch (part[0].length - i - 1) {
					case 0: tmpnewchar = tmpnewchar; break;
					case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
					case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
					case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
					case 4: tmpnewchar = tmpnewchar + "万"; break;
					case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
					case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
					case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
					case 8: tmpnewchar = tmpnewchar + "亿"; break;
					case 9: tmpnewchar = tmpnewchar + "十"; break;
				}
				newchar = tmpnewchar + newchar;
			}
			//替换所有无用汉字，直到没有此类无用的数字为止
			while (newchar.search("零零") != -1 || newchar.search("零亿") != -1 || newchar.search("亿万") != -1 || newchar.search("零万") != -1) {
				newchar = newchar.replace("零亿", "亿");
				newchar = newchar.replace("亿万", "亿");
				newchar = newchar.replace("零万", "万");
				newchar = newchar.replace("零零", "零");
			}
			//替换以“一十”开头的，为“十”
			if (newchar.indexOf("一十") == 0) {
				newchar = newchar.substr(1);
			}
			//替换以“零”结尾的，为“”
			if (newchar.lastIndexOf("零") == newchar.length - 1) {
				newchar = newchar.substr(0, newchar.length - 1);
			}
			return newchar;
		}
	</script>
</body>

</html>